<?php
/**
 * Created by PhpStorm.
 * User: lingyun
 * Date: 2018/2/23
 * Time: 20:51
 * Desc: 总后台商品服务层
 */
namespace app\mall\service;
use app\mall\model\GoodsCategory;
use think\Controller;
use think\model;
/**
 * 用户类服务层
 */
class GoodsService extends Controller{
	/**
	 * 添加分类
	 */
	public function add_category($data){
		$GoodsCategory = new GoodsCategory();
		$result = $GoodsCategory->add($data);
		$result['code'] == 1?$this->success('保存成功',''):$this->error('保存失败','');
	}
	/**
	 * 编辑分类
	 * @return [type] [description]
	 */
	public function edit_category($data,$id){
		$GoodsCategory = new GoodsCategory();
		$result =  $GoodsCategory->edit($data,$id);
		$result['code'] == 1?$this->success('保存成功',''):$this->error('保存失败','');
	}

    /**
     * @Author  lingyun
     * @Desc    商品的五套图集
     * @param $id   商品id
     */
	public function goods_images($id){

    }

    /**
     * @Author  lingyun
     * @Desc    商品品论列表
     * @param $urlcode
     * @param string $get
     * @return mixed
     */
    public function litbioa($urlcode,$get=''){
        $list = GoodsComment::where('content','like','%'.$get.'%' )->paginate(10, false, ['query' =>$urlcode]);
        $userservice = new UserService;
        foreach ($list as $key => &$value) {
            $value->shifouxianshi  = $value->is_show==1?"是":"不显示";
            $value->shifouxianshicn  = $value->is_show==1?"不显示":"显示";
            $value->goodsname   =   $this->getgoodbyid($value->goods_id)['name'];
            $value->addtime   =   date('Y-m-d H:i',$value->addtime);
            if($value->uid){
                $value->nickname  = $userservice->getuserinfobyuid($value->uid)['nickname'];
            }else{
                $value->nickname  ='匿名';
            }
        }
        return $list;
    }

    /**
     * @Author  lingyun
     * @Desc    设置商品评论是否显示
     * @param $id  商品评论id
     * @return mixed
     */
    public function ishowsLook($id){
        $commit = $this->getcommintbyid($id);
        $comit  =  new 	GoodsComment;
        if($commit['is_show']){
            $data=['is_show'=>'0'];
            $se =  DbShowcollo::refresh($comit,'id',$id,$data);
            return $se;
        }else{
            $data=['is_show'=>'1'];
            return DbShowcollo::refresh($comit,'id',$id,$data);
        }
    }

    /**
     * 获取一条评论
     * @return [type] [description]
     */
    public function getcommintbyid($id){
        return GoodsComment::get($id)->toArray();
    }

}

